package com.example.demo.controller;

import com.example.demo.handle.EmailSender;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class EmailController {
    @Resource
    private EmailSender emailSender;

    @GetMapping("/send-mail")
    public ResponseEntity<String> sendMail() {
        try {
            emailSender.sendScoreSheet();
            return new ResponseEntity<>("邮件发送成功", HttpStatus.OK);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseEntity<>("邮件发送失败：" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}